-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make resolution cross-env in filesystem plugin and base package #1128
Make resolution cross-env in filesystem plugin and base package #1128
Conversation
* Stop using hardcoded path separators. These are not the same across environments. * Use path.relative for relative resolution instead of replace. This normalizes paths first * Cutoff the extension using path.basename and path.extname, which works across environments * Prefix with a slash if necessary
I've not added tests yet, and not thoroughly tested this in general.
|
This looks great to me. Let me know when you're ready to merge. I am! |
@tannerlinsley I just want to add a few tests to cover this in perpetuity. Currently making sure this all works with nested paths et cetera, adding tests:
|
Awesome! |
FWIW: I tested out nested paths etc; these all work as intended.
|
This is covered by git and other svn; it will automatically correct the linebreak style. https://eslint.org/docs/rules/linebreak-style#using-this-rule-with-version-control-systems > For example, the default behavior of git on Windows systems is to convert LF linebreaks to CRLF when checking out files, but to store the linebreaks as LF when committing a change This rule is therefore redundant.
This correctly passes environment variables to the process across environments.
Single quotes won't work across shells. In this case the argument never needs quotes.
Does not yet solve the build issue on windows. The issue lies in |
} | ||
// Instead of using path.sep, we always want to test for all of them. This makes | ||
// the tests consistent and means we can write tests with either separator | ||
const escapedPathSeps = escapeRegExp(`${path.win32.sep}${path.posix.sep}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genius
This is where the static info is passed into the client bundle: https://github.com/nozzle/react-static/blob/master/packages/react-static/src/bootstrapApp.js#L23-L27 The export process requires the bundle (which is just a commonjs webpack bundle) and calls this function with the siteData, which is then pushed throughout the app via react context. It's a shame we have to do it this way, but React context instances don't survive across bundles. |
The actual context instance lives here: https://github.com/nozzle/react-static/blob/master/packages/react-static/src/browser/context/staticInfoContext.js If the staticInfo context isn't there, then it probably means it's not being passed to the bundle function in export here: https://github.com/nozzle/react-static/blob/master/packages/react-static/src/static/exportRoute.js#L111 Or, it's not being properly embedded into Any thoughts? |
@tannerlinsley For funsies I've changed // Hydrate sharedDataByHash with the embedded routeInfo
- Object.keys(sharedHashesByProp).forEach(propKey => {
+ Object.keys(sharedHashesByProp || {}).forEach(propKey => {
sharedDataByHash[sharedHashesByProp[propKey]] = sharedData[propKey]
}) Just so it would pass this part (I did not put any I'm a bit at a loss. Currently looking through the files you just linked. |
Let me pull in your PR and try it out. |
In order to reproduce:
Create a new project with the basic template
To update the local package:
|
Alright. More information! I've gone ahead and tried to figure out where exactly it starts losing information. So I logged after the line you linked from { template: '../src/pages/404.js',
sharedHashesByProp: {},
data: {},
path: '404',
sharedData: {},
siteData: {} }
{ template: '../src/pages/about.js',
sharedHashesByProp: {},
data: {},
path: 'about',
sharedData: {},
siteData: {} }
{ template: '../src/pages/blog.js',
sharedHashesByProp: {},
data: {},
path: 'blog',
sharedData: {},
siteData: {} }
{ template: '../src/pages/index.js',
sharedHashesByProp: {},
data: {},
path: '/',
sharedData: {},
siteData: {} } At this point it's all good! I'm now moving on to figure out if the context is correctly set and retained. |
Awesome! Yeah, once you know the data pipeline, it's relatively easy to track. |
Again, if that's the bug, then it's a cross-env one like you're thinking. |
What exactly am I looking for? I see Object.defineProperty(exports, "staticInfoContext", {
enumerable: true,
get: function get() {
return _staticInfoContext["default"];
}
});
exports.useStaticInfo = void 0;
var _react = __webpack_require__(0);
var _staticInfoContext = _interopRequireDefault(__webpack_require__(47));
var useStaticInfo = function useStaticInfo() {
return (0, _react.useContext)(_staticInfoContext["default"]);
};
exports.useStaticInfo = useStaticInfo;
/***/ }),
/* 47 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
ar _interopRequireDefault = __webpack_require__(6);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(__webpack_require__(0)); // eslint-disable-next-line
var context = _react["default"].createContext({});
if (typeof document !== 'undefined') {
context = _react["default"].createContext(window.__routeInfo);
}
var _default = context;
exports["default"] = _default; ...Which is the code to create the context, aka the hook. This code is minified inside function(e, t, n) {
"use strict";
var r = n(2);
Object.defineProperty(t, "__esModule", {
value: !0
}), Object.defineProperty(t, "staticInfoContext", {
enumerable: !0,
get: function() {
return i.default
}
}), t.useStaticInfo = void 0;
var o = n(0),
i = r(n(103));
t.useStaticInfo = function() {
return (0, o.useContext)(i.default)
}
},
function(e, t, n) {
"use strict";
function r(e) {
return (r = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
return typeof e
} : function(e) {
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
})(e)
}
function o(e) {
return (o = "function" == typeof Symbol && "symbol" === r(Symbol.iterator) ? function(e) {
return r(e)
} : function(e) {
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : r(e)
})(e)
}
n.r(t);
var i = n(0),
a = n.n(i),
u = (n(111), n(12), n(9)),
l = n.n(u),
c = n(47),
s = n.n(c);
...
function(e, t, n) {
"use strict";
var r = n(2);
Object.defineProperty(t, "__esModule", {
value: !0
}), t.default = void 0;
var o = r(n(0)),
i = o.default.createContext({});
"undefined" != typeof document && (i = o.default.createContext(window.__routeInfo));
var a = i;
t.default = a
} |
Okay. It's okay that it's bundled inside the The fact that it's inside the static bundle is very bad though and confirms my hunch. Webpack is bundling the So now the question is, why would it be externalizing that file in my environment, and not yours? |
Do you see anything fishy here? https://github.com/nozzle/react-static/blob/master/packages/react-static/src/static/webpack/webpack.config.prod.js#L165-L179 |
Ah; gimme a minute or three. I'll be back with either a fish on a hook or a single tear. |
🐟 🦈 |
@tannerlinsley let's wait for CI; Amended CHANGELOG.md and the description of this PR. (🎉 🎉 🎉) There might be more cross-env issues in other plugins, but at least the starter works again. Feel free to ping/tag me whenever you hit one! |
Curiously, are you formatting with the |
I think it automatically calls that in my IDE |
Looks like the only thing that needs to be updated is the xml snapshots, which are actually updated in master. Going to merge and go from there! |
For posterity: This is likely one of the best PR's and Github interactions I have ever had. |
Thanks for spending the time explaining how all the moving parts work together!
Yeah I saw those tests fail -- is that because of a change I made? I didn't touch the XML package so I found it weird. On the other hand; it's of course building a sitemap and I changed paths :P EDIT: nvm, I see it's failing in that other pr and on travis |
My pleasure! |
I updated the XML code in another PR, but not the snapshots. |
Code is now available in the 7.0.8 release! 🎉🎉🎉 |
@SleeplessByte did you test building the site to an absolute path (e.g. |
Hi, I'm still getting the #1122 error in the 7.0.9 release. I'm running through cmd.exe on windows: |
Sidenote, in dev I get the following error with the hotloader (cc @tannerlinsley)
Need to look at this weird mangled hot loading webpack-dev-server url' @digitalkaoz no I did not. Let me know if that currently breaks or not. I'm happy to figure that one out too if it doesnt work! @LukeStanislaus you're on 7.0.5 Edit: Apparently this was a known issue and has nothing to do with this PR 🗡 |
When I look at the documentation for hot module replacement, it seems the current webpack.dev config file is outdated. I'll open another PR so you can check it out. Edit: Fixed in #1135 |
Hey, you can Check it yourself (im on vacation). Just build to `/tmp/foo`
using the paths.* Config option
Thanks
Robert
Derk-Jan Karrenbeld <notifications@github.com> schrieb am Di., 16. Apr.
2019, 17:58:
… Sitenote:
Uncaught SyntaxError: The URL 'http:/[http//localhost]:8080' is invalid
Need to look at this weird mangled hot loading webpack-dev-server url
@digitalkaoz <https://github.com/digitalkaoz> no I did not. Let me know
if that currently breaks or not. I'm happy to figure that one out too if it
doesnt work!
@LukeStanislaus <https://github.com/LukeStanislaus> you're on 7.0.5
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1128 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAR612b4aQRjfg_dQXGDwvh621xrrgKWks5vhnGtgaJpZM4cwlE5>
.
|
This issue still seems to be happening in August. Using a Windows ten laptop with latest downloads from yarn. init().catch(e => { TypeError: Cannot read property 'catch' of undefined |
@FayeB can you open a new issue for that last thing? |
Description
Changes the resolution in
react-static-plugin-source-filesystem
to be cross-env compatible.path.relative
for relative resolution instead of replace. This normalises paths first, so it works across environments.path.basename
andpath.extname
, which works across environments.location
root, not site root.This works with
path.resolve(...)
and./src/pages
.Changes the resolution in
react-static
to be cross-env compatible.join
whenever dealing with real pathsAdditionally, changes the
webpack.config.prod.js
to use cross-env resolution for the paths that are considered external.Changes/Tasks
Motivation and Context
Fixes #1094
Fixes #1122
Fixes #1123
Screenshots (if appropriate):
Types of changes
Checklist: